#include <ximera/scripting/lua/virtualmachine.hpp>

#include <ximera/math/vector3.hpp>
#include <ximera/math/aabb.hpp>

#include <luabind/dependency_policy.hpp>
#include <luabind/operator.hpp>

namespace ximera { namespace scripting { namespace lua
{
    void VirtualMachine::bindMathLib()
    {
        using namespace math;
        using namespace luabind;

        module(_state, "ximera")
        [
            namespace_("math")
            [
                class_<Vector3>("Vector3")
                    .def(constructor<>())
                    .def(constructor<Real>())
                    .def(constructor<Real, Real, Real>())
                    .def("length", &Vector3::length)
                    .def("lengthSquared", &Vector3::lengthSquared)
                    .def("dotProduct", &Vector3::dotProduct)
                    .def("crossProduct", &Vector3::crossProduct)
                    .def("normalize", &Vector3::normalize)
                    .def("asNormal", &Vector3::asNormal)                    
                    .def("at", (Real& (Vector3::*)(int)) &Vector3::operator[], dependency(result, _1))
                    .def("at", (Real const& (Vector3::*)(int) const) &Vector3::operator[], dependency(result, _1))
                    .def_readwrite("x", &Vector3::x)
                    .def_readwrite("y", &Vector3::y)
                    .def_readwrite("z", &Vector3::z)
                    .def(const_self == const_self)
                    .def(const_self < const_self)
                    .def(const_self + const_self)
                    .def(const_self - const_self)
                    .def(const_self * const_self)
                    .def(const_self * other<Real>())
                    .def(other<Real>() * const_self)
                    .def(const_self / other<Real>())
                    .def(-const_self)
                ,
                class_<Aabb>("Aabb")
            ]
        ];
    }
}}}
